add_library(Selah SHARED)

target_sources(Selah PRIVATE
    Selah.h

    Core/Macros.h
    Core/GLFW.h
    Core/InputTypes.h
    Core/Application.cpp
    Core/Application.h
    Core/Window.cpp
    Core/Window.h

    Core/ShaderReflector.h
    Core/ShaderReflector.cpp

    Core/Math/Math.h
    Core/Math/ScalarTypes.h
    Core/Math/VectorTypes.h
    Core/Math/Quaternion.h
    Core/Math/MatrixMath.h
    # Core/Math/VectorSwizzle2.inl.h
    # Core/Math/VectorSwizzle3.inl.h
    # Core/Math/VectorSwizzle4.inl.h


    Scene/Scene.h
    Scene/Camera/Camera.h
    Scene/Camera/Camera.cpp
    Scene/Camera/CameraController.h
    Scene/Camera/CameraController.cpp
    Scene/tiny_obj_loader.h
    Scene/OBJLoader.h
    Scene/OBJLoader.cpp
    Scene/stb_image.h
    Scene/stb_image_write.h
    Scene/tiny_gltf.h
    Scene/GLTFLoader.h
    Scene/GLTFLoader.cpp
    Scene/TextureLoader.h
    Scene/TextureLoader.cpp
    # Scene/DDSTextureLoader12.h
    # Scene/DDSTextureLoader12.cpp
)

# ImGui source files
target_sources(Selah PRIVATE
    ../External/imgui/imconfig.h
    ../External/imgui/imgui_demo.cpp
    ../External/imgui/imgui_draw.cpp
    ../External/imgui/imgui_impl_dx12.h
    ../External/imgui/imgui_impl_dx12.cpp
    ../External/imgui/imgui_impl_glfw.h
    ../External/imgui/imgui_impl_glfw.cpp
    # ../External/imgui/imgui_impl_vulkan.h
    # ../External/imgui/imgui_impl_vulkan.cpp
    ../External/imgui/imgui.h
    ../External/imgui/imgui.cpp
    ../External/imgui/imgui_widgets.cpp
    ../External/imgui/imgui_tables.cpp
    ../External/imgui/imgui_internal.h
    ../External/imgui/imstb_rectpack.h
    ../External/imgui/imstb_textedit.h
    ../External/imgui/imstb_truetype.h
    # ../../external/imgui_addons/imguinodegrapheditor/imguinodegrapheditor.h
    # ../../external/imgui_addons/imguinodegrapheditor/imguinodegrapheditor.cpp
)


target_link_libraries(Selah

PUBLIC
    imgui
    dxc # DirectX Shader Compiler ()
    d3d12
    eigen
#     $<$<BOOL:${FALCOR_HAS_CUDA}>:CUDA::cuda_driver>
#     $<$<BOOL:${FALCOR_HAS_CUDA}>:CUDA::cudart_static>

PRIVATE
    glfw
    $<$<BOOL:${SELAH_HAS_D3D12}>:d3d12>
    $<$<BOOL:${SELAH_HAS_D3D12_AGILITY_SDK}>:agility-sdk>
    # Windows system libraries.
    $<$<PLATFORM_ID:Windows>:shcore.lib>
    $<$<PLATFORM_ID:Windows>:shlwapi.lib>
    $<$<PLATFORM_ID:Windows>:comctl32.lib>
    $<$<PLATFORM_ID:Windows>:setupapi.lib>  # Used in MonitorInfo
    # Linux system libraries.
    # $<$<PLATFORM_ID:Linux>:gtk3>
    
)

target_compile_definitions(Selah
# PRIVATE
#     STB_IMAGE_STATIC
PUBLIC
    $<$<CONFIG:Release>:NDEBUG>
    $<$<CONFIG:Debug>:_DEBUG>

    # dx12 debug layer
    $<$<CONFIG:Debug>:DX12_ENABLE_DEBUG_LAYER>

    # Windows.
    $<$<PLATFORM_ID:Windows>:NOMINMAX>  # do not define min/max macros
    $<$<PLATFORM_ID:Windows>:UNICODE>   # force character map to unicode
    # MSVC C++ library.
    $<$<CXX_COMPILER_ID:MSVC>:_USE_MATH_DEFINES>
    $<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>
    $<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>
    $<$<CXX_COMPILER_ID:MSVC>:_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING>
    $<$<CXX_COMPILER_ID:MSVC>:_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS>
    # Clang.
    $<$<CXX_COMPILER_ID:Clang>:_MSC_EXTENSIONS> # enable MS extensions

    

PRIVATE
    SELAH_DLL
    $<$<PLATFORM_ID:Windows>:IMGUI_API=__declspec\(dllexport\)>
)

target_include_directories(Selah
    PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}
)

set_target_properties(Selah PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${SELAH_RUNTIME_OUTPUT_DIRECTORY}
    LIBRARY_OUTPUT_DIRECTORY ${SELAH_LIBRARY_OUTPUT_DIRECTORY}
)

add_custom_command(TARGET Selah POST_BUILD
    # COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DXIL_BINARY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/d3d12/$<CONFIG>
    COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DXC_BINARY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
    COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DXIL_BINARY} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
    # COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DXC_LIB_PATH}/dxcompiler.lib ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)